<template>
    <div class="madp-article-list">
        <div class="madp-row">
            <h3>链接素材（共{{ linkData.length }}篇）</h3>
            <el-input placeholder="请输入链接标题" maxlength="20" class="madp-article-title" v-model.trim="inputValue" @change="searchTitleBlurFn" suffix-icon="el-icon-search"></el-input>
        </div>
        <div class="madp-article-content">
            <div class="madp-add-content madp-add-list" v-if="permissions.cp_marketing_material_add" @click="addContent">
                <div class="madp-add-btn">
                    <i class="el-icon-circle-plus-outline"></i>
                    <p>添加链接</p>
                </div>
            </div>
            <div class="madp-add-content madp-add-list" v-for="(item, index) in linkData" :key="index">
                <div class="madp-add-content-item">
                    <div class="madp-add-release v-else" v-show="item.marketingState == 1">
                        内容未发布 &nbsp;
                        <el-tooltip content="文章内容未进行发布审核，不支持发送给客户哦" placement="top" effect="light">
                            <i class="el-icon-question"></i>
                        </el-tooltip>
                    </div>
                    <div class="madp-add-release" v-show="item.marketingState == 3">
                        有修改内容未发布 &nbsp;
                        <el-tooltip content="文章内容未进行发布审核，不支持发送给客户哦" placement="top" effect="light">
                            <i class="el-icon-question"></i>
                        </el-tooltip>
                    </div>
                    <div class="madp-list-content">
                        <div class="madp-list-left">
                            <div class="list-title">{{ item.title }}</div>
                            <div class="list-desc">
                                <p>{{ item.marketingDescribe }}</p>
                            </div>
                        </div>
                        <el-image class="madp-list-image" fit="contain" :src="item.marketingCover"></el-image>
                    </div>
                    <div class="madp-list-bottom">
                        <span>更新于{{ item.updateTime }}</span>
                        <div class="madp-list-bottom-btns">
                            <i class="el-icon-edit" v-if="permissions.cp_marketing_material_edit" @click="editRow(item)"></i>
                            <i class="el-icon-delete" v-if="permissions.cp_marketing_material_del" @click="deleteRow(item)"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 新增编辑文本 -->
        <el-dialog title="链接属性" v-if="dialogVisible" :visible.sync="dialogVisible" width="800px" :close-on-click-modal="false">
            <link-list-edit :activeObj="activeObj" :sendLinkList="linkForm" @newAndEditSaveLinkFn="newAndEditSaveLinkFn" @handleClose="dialogVisible = false"></link-list-edit>
        </el-dialog>
    </div>
</template>

<script>
import LinkListEdit from './link-list-edit';
import { getLinkList, deleteLink } from '@/api/customer-into/marketing-material';
import { mapGetters } from 'vuex';
export default {
    components: {
        LinkListEdit
    },
    props: {
        activeObj: {
            type: Object,
            default: () => {
                return {
                    activeIndex: 0
                };
            }
        }
    },
    data() {
        return {
            radio: '1',
            // 输入内容
            inputValue: null,
            linkData: [
                // {
                //     id: 1,
                //     title: '链接标题',
                //     marketingDescribe: '链接描述链接描述',
                //     marketingCover:
                //         'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
                //     updateTime: '2020-09-09 09:30:00',
                //     linkContent: '文章详细内容文章详细',
                // }
            ],
            // 表单
            linkForm: null,
            // 弹窗开关
            dialogVisible: false
        };
    },
    watch: {
        activeObj() {
            if (this.activeObj.activeIndex > 1) {
                this.inputValue = '';
                this.getLinkListFn();
            }
        }
    },
    computed: {
        ...mapGetters(['permissions'])
    },
    created() {
        this.getLinkListFn();
    },
    methods: {
        //   添加链接
        addContent() {
            this.linkForm = {
                marketingUrl: '',
                title: '',
                marketingDescribe: '',
                marketingCover: '',
                trackBehavior: false,
                trackDynamic: false,
                changeTitle: 0
            };
            this.dialogVisible = true;
        },
        // 编辑链接
        editRow(row) {
            this.linkForm = row;
            this.linkForm.changeTitle = 1;
            this.dialogVisible = true;
        },
        //删除链接
        deleteRow(row) {
            //   this.linkData.splice(row.id,1)
            this.deleteLinkFn(row.id);
        },
        //链接标题模糊查询或者分页查询
        getLinkListFn() {
            let obj = {
                title: this.inputValue,
                classification: this.activeObj.id
            };
            getLinkList(obj).then((res) => {
                if (res.data.code === 0) {
                    this.linkData = res.data.data;
                }
            });
        },
        //链接删除文章
        deleteLinkFn(id) {
            deleteLink(id).then((res) => {
                if (res.data.code === 0) {
                    this.$message({
                        message: '删除成功',
                        type: 'success'
                    });
                    this.getLinkListFn();
                }
            });
        },
        // 关闭弹窗
        newAndEditSaveLinkFn() {
            this.dialogVisible = false;
            this.getLinkListFn();
        },
        //模糊搜索
        searchTitleBlurFn() {
            this.getLinkListFn();
        }
    }
};
</script>

<style lang="scss" scoped>
.madp-article-content {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    margin-top: 10px;
    .madp-add-content {
        display: flex;
        cursor: pointer;
        width: 260px;
        min-height: 160px;
        height: 9.2rem;
        border: 1px solid #dcdfe6;
        margin: 10px;
        box-sizing: border-box;
        padding: 6px;
        .el-icon-circle-plus-outline {
            font-size: 20px;
        }
    }
}
.madp-add-box {
    display: flex;
    flex-wrap: wrap;
}
.madp-add-btn {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    margin: 0 auto;
    align-items: center;
}
.madp-add-list {
    position: relative;
    .madp-add-release {
        position: absolute;
        right: 0;
        top: 0;
        z-index: 10;
        font-size: 12px;
        cursor: pointer;
        width: fit-content;
        height: 20px;
        background: rgba(220, 223, 230, 0.8);
        text-align: right;
        border-radius: 2px;
    }
    .madp-add-content-item {
        width: 100%;
    }
    .madp-list-content {
        display: flex;
        justify-content: space-between;
        .madp-list-left {
            width: calc(100% - 6.25rem);
            .list-title {
                font-size: 16px;
                font-weight: bold;
                text-overflow: ellipsis;
                overflow: hidden;
                white-space: nowrap;
            }
        }
    }

    .list-desc p {
        width: 100%;
        height: 2.4rem;
        line-height: 1.2rem;
        font-size: 0.7rem;
        word-break: break-all;
        text-overflow: ellipsis;
        display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
        -webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
        -webkit-line-clamp: 2; /** 显示的行数 **/
        overflow: hidden; /** 隐藏超出的内容 **/
    }
    .madp-list-image {
        max-width: 80px;
        height: 80px;
    }
    .madp-list-bottom {
        height: fit-content;
        width: 100%;
        font-size: 0.75rem;
        border-top: 0.0625rem solid #dcdfe6;
        display: flex;
        padding: 6px 6px 0 0;
        position: absolute;
        bottom: 0;
        left: 0;
        justify-content: space-between;
        span {
            margin-left: 5px;
        }
        .el-icon-edit {
            font-size: 20px;
            margin-left: 10px;
            cursor: pointer;
        }
        .el-icon-delete {
            font-size: 20px;
            margin-left: 10px;
            cursor: pointer;
        }
        .el-icon-refresh {
            font-size: 20px;
            margin-left: 10px;
            cursor: pointer;
        }
        &-btns {
            display: flex;
        }
    }
}
.madp-row {
    margin-top: 10px;
    height: 40px;
    line-height: 40px;
    display: flex;
    justify-content: space-between;
}
.madp-article-title {
    width: 20%;
}
</style>
